/*
 * IShaderConstructor.h
 *
 *  Created on: 09.05.2012
 *      Author: Kirill Blinov
 *      Copyright: LGPL
 */

#ifndef ISHADERCONSTRUCTOR_H_
#define ISHADERCONSTRUCTOR_H_

#include "../BasicTypes.h"
#include "ShaderTypes.h"
#include "IShaderParamParser.h"

/*
 * It's a class to construct a shader with specified parameters set.
 */
class CShaderConstructor
{
friend class CResourceWarehouse;
private:
	std::string typeName;

	//Shader OpenGL ID
	GLuint programName;

	//Contains parameters for parser associated with this shader, can be extended or replaced by a Unit
	std::string loadedShaderParameters;

	std::vector<IShaderParamParser*> parsersArray;

	std::vector< std::string > sortedShaderTextures;

private:
	CShaderConstructor( std::string TypeName, GLuint ProgramName, std::vector<IShaderParamParser*> ParsersArray,
						std::string LoadedShaderParameters, std::vector< std::string > SortedShaderTextures );
	virtual ~CShaderConstructor();

	/*
	 * This function takes a string of tokens<Parameter:Type:Type:Value> and a shader,
	 * then parses tokens from the string and submit its values to shader.
	 * Return: string of unrecognized tokens.
	 */
	virtual bool ParseConfigurationString( const std::string ConfigurationString,
			                               IShaderProgram *ShaderProgram )const;

public:

	/*
	 * This function creates a shader with parameters set according to ConfigurationString
	 * income parameter. This string contains tokens<Parameter:Type:Value>. ConstructShader() uses
	 * ParseConfigurationString() to parse this string and converts parameter values to numbers ( float, int ),
	 * and submit them.
	 */
	virtual IShaderProgram* ConstructShader( const std::string ConfigurationString )const;

	std::string GetTypeName()const { return typeName; };

	/*
	 * Adds a parser to parsers list. If a parser which handles the same parameter name is already in a list
	 * a new parser will never be called for this parameter.
	 */
	void AddParamParser ( IShaderParamParser* Parser ) { parsersArray.push_back( Parser ); };

};

#endif /* ISHADERCONSTRUCTOR_H_ */
